export const getMenuRoutesByRole = (menuRoutes, roles) => {
  let arr = []
  menuRoutes.forEach(item => {
    arr.push(...setroles(roles, item))
  })
  return arr
}

function setroles(roles, item) {
  let array = []
  if (roles.includes(item.title)) {
    array.push(item)
  } else if (item.children) {
    let children = filterFn([...item.children], roles);
    item.children = children;
    array.push(item)
  }
  return array
}

function filterFn(children, roles) {
  let arr = [];
  for (var i = 0; i < children.length; i++) {
    if (roles.includes(children[i].meta.title)) {
      arr.push(children[i])
    }
  }
  return arr;
}